﻿
@using (Html.BeginForm("UserGroupPermissionSave", "Account", Html.ViewContext.RouteData.Values,FormMethod.Post))
{
    @Html.AntiForgeryToken()
    @Html.Hidden("selectPermissions", ((string)@ViewBag.SelectedRowIds), new {@style="width:350px" })
    
    <script type="text/javascript">
        //var selectedList = '@ViewBag.SelectedRowIds';
        var selectedIDs = '@ViewBag.SelectedRowIds'.split(";");
        function Permission_OnSelectionChanged(s, e) {
            if (e.visibleIndex < 0) return;
            var key = s.GetRowKey(e.visibleIndex);
            if (key == null) return;
            var index = selectedIDs.indexOf(key);
            if (e.isSelected&& index< 0) {
                selectedIDs.push(key);
            }
            else {
                if (index >= 0)
                    selectedIDs.splice(index,1);
            }
            $("#selectPermissions").val(selectedIDs.join(";"));
        };
    </script>
   @Html.DevExpress().RoundPanel(
            panelSettings =>
            {
                panelSettings.Name = "rpFeatures";
                panelSettings.HeaderText = "["+@ViewBag.GroupName+"]-权限编辑";
                panelSettings.ShowHeader = true;
                panelSettings.View = DevExpress.Web.ASPxRoundPanel.View.Standard;
                panelSettings.ControlStyle.BackColor = Color.White;
                //panelSettings.Width = 315;
                panelSettings.SetContent(() =>
                {
                    ViewContext.Writer.Write(

                        //Html.DevExpress().CheckBoxList(settings => {
                        //        settings.Name = "cblCheckGroup";
                        //        settings.Properties.ValueField = "PermissionId";
                        //        settings.Properties.TextField = "Name";
                        //        settings.Properties.ValueType = typeof(string);
                        //        settings.Properties.RepeatLayout = System.Web.UI.WebControls.RepeatLayout.Table;
                        //        settings.Properties.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
                        //        settings.Properties.RepeatColumns = 15;
                        //        settings.Properties.ItemSpacing = Unit.Pixel(5);
    
                        //        settings.PreRender = (sender, e) => {
                        //            ASPxCheckBoxList cbl = (ASPxCheckBoxList)sender;
                        //            foreach(ListEditItem item in cbl.Items) {
                        //                item.Selected = ViewBag.Students.Contains((string)item.Value);
                        //            }
                        //        };
                        //    })
                        //    .BindList(ViewBag.AllStudents)
                        //    .GetHtml()

                        @Html.DevExpress().GridView(
                        settings =>
                        {
                            settings.Name = "gridView_p";
                            DevControlHelper.InitDefaultPagerGridViewSettings(settings);
                            settings.Width = Unit.Pixel(1200);
                            settings.HtmlRowCreated += (s, e) =>
                            {
                                MVCxGridView grid = s as MVCxGridView;
                                if (e.VisibleIndex < 0) return;
                                var selected = grid.GetRowValues(e.VisibleIndex, "Selected");
                                if ((bool)selected)
                                {
                                    grid.Selection.SetSelection(e.VisibleIndex, true);
                                }
                            };

                            settings.SettingsPager.Visible = false;
                            settings.SettingsPager.Mode = GridViewPagerMode.ShowAllRecords;
                            settings.CallbackRouteValues = new { Controller = "Account", Action = "UserGroupPermissions", id = Html.ViewContext.RouteData.Values["id"] };

                            settings.KeyFieldName = "PermissionId";
                            settings.Columns.Add("PermissionType", "分类");
                            settings.Columns.Add("Name", "权限名称");
                            settings.Columns.Add("Module", "模块");
                            //settings.Columns.Add("Selected", "", MVCxGridViewColumnType.CheckBox).PropertiesEdit.;
                            
                            settings.CommandColumn.Visible = true;
                            settings.CommandColumn.ShowSelectCheckbox = true;
                            settings.ClientSideEvents.SelectionChanged = "Permission_OnSelectionChanged";


                        }).Bind(Model).GetHtml()

                    );
                });
            }).GetHtml()





    <br />

    <div style="width:1200px; text-align:right;">
        <input type="submit" class="webcar-button" value="保存" />
        <input type="button" class="webcar-button" value="取消" onclick="pageback();" />

    </div>
    <script type ="text/javascript">
        function pageback() {
            location.href = '@Url.Action("UserGroup")';
            
        }
    </script>
}

